<!-- Horizontal Form -->
<div class="box box-info" id="news-edit-app">
    <div class="box-header with-border">
        <h3 class="box-title">修改新闻</h3>
    </div>
    <!-- /.box-header -->
    <!-- form start -->
    <form class="form-horizontal">
        <div class="box-body">
            <div class="form-group">
                <label for="typeId" class="col-sm-2 control-label">新闻类型</label>
                <div class="col-sm-10">
                    <select name="type" id="typeId" class="=form-control">
                        <option value="0" :selected="news.type==0">行业资讯</option>
                        <option value="1" :selected="news.type==1">公司新闻</option>
                        <option value="2" :selected="news.type==2">新闻中心</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="nameId" class="col-sm-2 control-label">新闻标题</label>
                <div class="col-sm-10">
                    <input type="text" name="title" class="form-control" id="nameId" v-model="news.title">
                </div>
            </div>
            <div class="form-group">
                <label for="summaryId" class="col-sm-2 control-label">简介</label>
                <div class="col-sm-10">
                    <textarea id="summaryId" name="summary" cols="40" rows="4" class="form-control">{{news.summary}}</textarea>
                </div>
            </div>
            <div class="form-group">
                <label for="contentId" class="col-sm-2 control-label">新闻内容</label>
                <div class="col-sm-10">
                    <textarea id="contentId" name="content" cols="40" rows="6" class="form-control">{{news.content}}</textarea>
                </div>
            </div>
        </div>
        <!-- /.box-body -->
        <div class="box-footer">
            <button type="button" class="btn btn-default btn-cancel" @click="docancel">取消</button>
            <button type="button" class="btn btn-info pull-right btn-save" @click="saveOrUpdateNews()">
                保存
            </button>
        </div>
        <!-- /.box-footer -->
    </form>
</div>
<script type="text/javascript" src="bower_components/ztree/jquery.ztree.all.min.js"></script>
<script type="text/javascript" src="bower_components/layer/layer.js"></script>
<script type="text/javascript">
    var newsEditApp = new Vue({
        el: "#news-edit-app",
        data: {
            news: {}
        },
        methods: {
            saveOrUpdateNews: function () {
                //添加数据
                console.log(newsEditApp.news.id);
                let formData = new FormData(document.querySelector("form"));
                formData.append("id",newsEditApp.news.id);
                if (!formData) {
                    alert('获取表单数据异常!');
                    return;
                }
                //发起axios post 请求 ,向后端提交数据
                axios({
                    method: 'post',
                    url: "/f-news/edit",
                    data: formData
                }).then(res => {
                    let result = res.data;
                    if (result.state == 2000) {
                        alert('操作成功!');
                        this.docancel();
                    } else {
                        alert(result.message);
                    }
                })
            },
            docancel: function () {
                //跳转到角色列表视图
                $('#mainContentId').load('/sys/newsListPage');
            }
        },
        mounted() {
            let title = $('#mainContentId').data("title");
            axios({
                url: '/f-news/getNewsByName?title=' + title,
                method: 'get',
            }).then(function (response) {
                newsEditApp.news = response.data;
            })
        }
    })
</script>
    
    
    
    
    
    
    